package com.dragon.www.haier.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dragon.www.haier.R;
import com.dragon.www.haier.util.StringUtil;

/**
 * Created by liqp on 2016/10/27.
 */
public class SmartItemView extends LinearLayout{
    private final String NAMESPACE = "http://schemas.android.com/apk/res-auto";
    private String desc;
    private String stringImageID;
    private ImageView imageIcon;
    private TextView tv_name;

    public SmartItemView(Context context) {
        super(context);
    }

    public SmartItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        desc = attrs.getAttributeValue(NAMESPACE, "name");
        stringImageID = attrs.getAttributeValue(NAMESPACE, "Image");
        initView();
    }

    public SmartItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void initView() {

        View view = View.inflate(getContext(), R.layout.smart_item, this);
        imageIcon = (ImageView) view.findViewById(R.id.img_icon);
        tv_name = (TextView) view.findViewById(R.id.txt_name);

        int ImageID=Integer.parseInt(StringUtil.splitResouceID(stringImageID));
        imageIcon.setImageResource(ImageID);
        tv_name.setText(desc);
    }
}


